home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectInput / MultiMapper / Multidi.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-31  |  5.2 KB  |  117 lines

  1. //-----------------------------------------------------------------------------
  2. // File: MultiDI.h
  3. //
  4. // Desc: Multiple user DirectInput support using action mapping
  5. //
  6. // Copyright (C) 1995-2001 Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef MULTIDI_H
  9. #define MULTIDI_H
  10. #include <dinput.h>
  11.  
  12.  
  13. // E_DIUTILERR_PLAYERWITHOUTDEVICE is returned by the manager class after configuring
  14. // device, and there's a player that hasn't been assigned a device.
  15. #define E_DIUTILERR_PLAYERWITHOUTDEVICE MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,997)
  16.  
  17. // E_DIUTILERR_DEVICESTAKEN is returned by the manager class when one player
  18. // on the machine has enough RECENT devices to prevent other players from 
  19. // playing. This return code is needed because this sample attempts to give 
  20. // all RECENT devices to that player.
  21. #define E_DIUTILERR_DEVICESTAKEN MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,998) 
  22.  
  23. // E_DIUTILERR_TOOMANYUSERS is returned by the manager class when the number of 
  24. // players exceeds the number of devices present on the system. For example, 
  25. // if you ask for 4 players on a machine that only has a keyboard and mouse,
  26. // you're 2 short of what you need. 
  27. #define E_DIUTILERR_TOOMANYUSERS MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,999)
  28.  
  29.  
  30.  
  31. //-----------------------------------------------------------------------------
  32. // Name: class CMultiplayerInputDeviceManager
  33. // Desc: Input device manager using DX8 action mapping
  34. //-----------------------------------------------------------------------------
  35. class CMultiplayerInputDeviceManager
  36. {
  37. public:
  38.     struct PlayerInfo
  39.     {
  40.         DWORD                dwPlayerIndex;         // 0-based player number 
  41.         TCHAR                strPlayerName[MAX_PATH]; // player name
  42.         DWORD                dwMaxDevices;          // max number of elements in pDevices array
  43.         DWORD                dwNumDevices;          // current number of elements in pDevices array
  44.         BOOL                 bFoundDeviceForPlayer; // if a device has been found for this player yet
  45.     };
  46.     
  47.     struct DeviceInfo
  48.     {
  49.         LPDIRECTINPUTDEVICE8  pdidDevice;           // dinput device pointer
  50.         PlayerInfo*           pPlayerInfo;          // Player who owns this device
  51.         BOOL                  bRelativeAxis;        // TRUE if device is using relative axis
  52.         BOOL                  bMapsPri1Actions;     // TRUE if device maps pri 1 actions
  53.         BOOL                  bMapsPri2Actions;     // TRUE if device maps pri 2 actions
  54.         LPVOID                pParam;               // app defined pointer assoicated with this device
  55.         DIDEVICEINSTANCE      didi;                 // device instance info
  56.     };
  57.     
  58.     typedef HRESULT (CALLBACK *LPDIMANAGERCALLBACK)(CMultiplayerInputDeviceManager::PlayerInfo* pPlayerInfo, CMultiplayerInputDeviceManager::DeviceInfo* pDeviceInfo, const DIDEVICEINSTANCE* pdidi, LPVOID);
  59.     
  60. private:
  61.     BOOL                    m_bCleanupCOM;
  62.     HWND                    m_hWnd;
  63.     
  64.     LPDIRECTINPUT8          m_pDI;
  65.     DIACTIONFORMAT*         m_pdiaf;
  66.     
  67.     PlayerInfo**            m_pUsers;
  68.     DWORD                   m_dwNumUsers;    
  69.  
  70.     DeviceInfo*             m_pDeviceList;
  71.     DWORD                   m_dwNumDevices;
  72.     DWORD                   m_dwMaxDevices;    
  73.     
  74.     LPDIMANAGERCALLBACK     m_AddDeviceCallback;
  75.     LPVOID                  m_AddDeviceCallbackParam;
  76.     
  77.     TCHAR*                  m_strKey;
  78.     HKEY                    m_hKey;
  79.     
  80. public:
  81.     static BOOL CALLBACK StaticEnumSuitableDevicesCB( LPCDIDEVICEINSTANCE pdidi, LPDIRECTINPUTDEVICE8 pdidDevice, DWORD dwFlags, DWORD dwRemainingDevices, VOID* pContext );
  82.     static BOOL CALLBACK StaticBuildDeviceListCB( LPCDIDEVICEINSTANCE pdidi, VOID* pContext );
  83.     
  84.     // Device control
  85.     BOOL EnumDevice( const DIDEVICEINSTANCE* pdidi, LPDIRECTINPUTDEVICE8 pdidDevice, DWORD dwFlags, DWORD dwDeviceRemaining );
  86.     BOOL BuildDeviceListCB( LPCDIDEVICEINSTANCE pdidi ); 
  87.     
  88.     HRESULT AddDevice( DeviceInfo* pDeviceInfo, BOOL bForceReset );
  89.     HRESULT GetDevices( DeviceInfo** ppDeviceInfo, DWORD* pdwNumDevices );
  90.     HRESULT ConfigureDevices( HWND hWnd, IUnknown* pSurface, VOID* pCallback, DWORD dwFlags, LPVOID pvCBParam );
  91.     DWORD   GetNumDevices() { return m_dwNumDevices; }
  92.     VOID    UnacquireDevices();
  93.     VOID    SetFocus( HWND hWnd );
  94.     PlayerInfo* LookupPlayer( TCHAR* strPlayerName );
  95.     HRESULT SaveDeviceOwnershipKeys();
  96.     VOID    DeleteDeviceOwnershipKeys();
  97.     HRESULT UpdateDeviceOwnership();
  98.     HRESULT AssignDevices();
  99.     HRESULT VerifyAssignment();
  100.     HRESULT AddAssignedDevices( BOOL bResetMappings );
  101.     
  102.     HRESULT BuildDeviceList();
  103.     VOID    CleanupDeviceList();
  104.     
  105.     // Construction
  106.     HRESULT SetActionFormat( DIACTIONFORMAT* pdiaf, BOOL bReenumerate, BOOL bResetOwnership, BOOL bResetMappings );
  107.     HRESULT Create( HWND hWnd, TCHAR* strUserNames[], DWORD dwNumUsers, DIACTIONFORMAT* pdiaf, LPDIMANAGERCALLBACK AddDeviceCallback, LPVOID pCallbackParam, BOOL bResetOwnership, BOOL bResetMappings );
  108.  
  109.     CMultiplayerInputDeviceManager( TCHAR* strRegKey );
  110.     ~CMultiplayerInputDeviceManager();
  111.     VOID Cleanup();
  112. };
  113.  
  114. #endif
  115.  
  116.  
  117.